package com.liCheng.service.user;

import com.liCheng.dao.user.UserMapper;
import com.liCheng.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Scope("prototype")
@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;//声明UserMapper接口引用

    /**
     * 模糊查询
     * @param user
     * @return
     */
    @Override
    public List<User> findUsersWithConditions(User user) {
        try {
            return userMapper.getUserList(user);//调用DAO方法实现查询
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
    }
    public UserMapper getUserMapper() {
        return userMapper;
    }

    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }


    /**
     * 添加
     * @param user
     * @return
     */
    @Override
    public boolean addNewUser(User user) {
        boolean result=false;
        try {
            if (userMapper.add(user)==1){
                result=true;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    /**
     * 修改
     * @param user
     * @return
     */
    @Override
    public int updateUser(User user) {
        try {
            return userMapper.userUpdate(user);//调用DAO方法实现查询
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 删除
     * @param user
     * @return
     */
    @Override
    public int delUser(User user) {
        try {
            return userMapper.userDel(user);//调用DAO方法实现查询
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
    }


}
